package cn.edu.scnu.semart.goods.mapper;

import cn.edu.scnu.semart.model.goods.Favorite;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * 用户收藏Mapper接口
 */
@Mapper
public interface FavoriteMapper extends BaseMapper<Favorite> {

    /**
     * 查询所有（包括逻辑删除）的收藏记录
     */
    @Select("SELECT * FROM user_favorite WHERE user_id = #{userId} AND goods_id = #{goodsId} LIMIT 1")
    Favorite selectAnyFavorite(@Param("userId") Integer userId, @Param("goodsId") Integer goodsId);

    /**
     * 恢复收藏（将deleted=1的记录恢复为0）
     */
    @Update("UPDATE user_favorite SET deleted = 0 WHERE id = #{id}")
    int restoreFavorite(@Param("id") Integer id);
} 